import { Component } from 'vue';
import { ProcessDefinitionKeyEnum } from '@/constants/enum';
const files = require.context('./', true, /\.vue$/);

export type FlowComponentsKeyType =
  | 'FactorAudit'
  | 'FootprintAccounting'
  | 'ActiveDataFill'
  | 'SupplierForm';
export type FlowComponentsType = {
  [key in FlowComponentsKeyType]: Component;
};

export const config: {
  [key in keyof typeof ProcessDefinitionKeyEnum]: {
    componentName: FlowComponentsKeyType;
  };
} = {
  [ProcessDefinitionKeyEnum.COOPERATION_MODEL_APPROVAL]: {
    componentName: 'FootprintAccounting'
  },
  [ProcessDefinitionKeyEnum.PCF_FACTOR_APPROVAL]: {
    componentName: 'FactorAudit'
  },
  [ProcessDefinitionKeyEnum.ACTIVITY_DATA_FILL_TASK]: {
    componentName: 'ActiveDataFill'
  },
  [ProcessDefinitionKeyEnum.SUPPLIER_FORM_APPROVAL]: {
    componentName: 'SupplierForm'
  }
};

const components = {};
files.keys().forEach(key => {
  const name = files(key).default.name;
  if (name) {
    const component = files(key).default;
    (components as any)[name] = component;
  }
});

export default components as FlowComponentsType;
